from fastapi import FastAPI, APIRouter, Request
import uvicorn
from pydantic import BaseModel
from pyparsing import List, wraps


port = 9999


class A(BaseModel):
    name: str


class B(BaseModel):
    names: List[A]


app = FastAPI()
router = APIRouter()


def Recv(func):
    @wraps(func)
    def wrapper(*args, request: Request, **kwargs):
        print(str(request.url).split(str(port))[1])
        result = func(*args, **kwargs, request=request)
        return result
    return wrapper


@router.post("/test/post")
@Recv
def testpost(b: B, request: Request):
    return f"Current URL: {request.url}"


@router.get("/test/get")
@Recv
def testget(request: Request):
    return f"Current URL: {request.url}"


app.include_router(router)


if __name__ == "__main__":
    uvicorn.run("main:app", host="0.0.0.0", port=port, reload=True)
